package com.lixiaoyu.service.impl;

import com.lixiaoyu.dao.ExpressDB;
import com.lixiaoyu.entity.Express;
import com.lixiaoyu.entity.ExpressBox;
import com.lixiaoyu.service.ExpressService;

/**
 * 业务逻辑层
 */
public class ExpressServiceImpl implements ExpressService{

    ExpressDB expressDB = new ExpressDB();

    /**
     *
     * @param admin 代表管理员
     * @param a  进行的操作    1增   2删   3改   4查
     */
    @Override
    public String adminLogin(String admin, int a) {

        return "没有查到数据";
    }

    /**
     *
     * @param user 代表普通用户
     * @param a 进行的操作   1 增
     */
    @Override
    public String userLogin(String user, int a) {

        return "没有查到数据";
    }

    /**
     * 查询账号和密码
     * @param userName
     * @param passWord
     * @return
     */
    @Override
    public String[][] getUserPassWord(String userName, int passWord) {
        String[][] PW = expressDB.getUserPassWord(userName);
        return PW;
    }

    /**
     * 根据取件码查询
     * @param getExpressCode
     * @return
     */
    @Override
    public String[][] selectUserExpress(int getExpressCode) {

        String[][] expressList = expressDB.getSelectUserExpress(getExpressCode);
        if(expressList.length > 1){
            System.out.println("查询取件码有误 请重新输入");
            return null;
        }
        if(expressList[0][2] != null){
            System.out.println("查询到的快递是:");
            System.out.println("快递单号:"+expressList[0][2]);
            System.out.println("快递公司:"+expressList[0][3]);
            System.out.println("快递柜号:"+expressList[0][1]);
            System.out.println("取件码号:"+expressList[0][0]);
        }else{
            System.out.println("没有此快递！！");
        }


        return expressList;
    }

    /**
     * 删除 取件码快递
     * @param getExpressCode
     */
    @Override
    public void deleteUserExpress(int getExpressCode) {
        expressDB.deleteUserExpress(getExpressCode);
    }

    /**
     * 增加快递
     * @param express
     */
    @Override
    public void addAdminExpress(Express express) {

        ExpressBox expressBox = expressDB.addAdminExpress(express);
        System.out.println("取件码是:"+expressBox.getGetExpressCode());
        System.out.println("取件柜是:"+expressBox.getExpressBoxCode());
    }

    @Override
    public int updateAdminExpress(int next, String next1, String next2) {

        return expressDB.updateAdminExpress(next,next1,next2);
    }

    @Override
    public int selectAdminExpress() {
        String[][] selectExpressLliset = expressDB.selectAdminExpress();

        if(selectExpressLliset != null){
            for(int i = 0; i < selectExpressLliset.length; i++){
                if(selectExpressLliset[i][0] != null){
                    System.out.print("取件码是:"+selectExpressLliset[i][0]);
                    System.out.print("||");
                    System.out.print("取件柜是:"+selectExpressLliset[i][1]);
                    System.out.print("||");
                    System.out.print("快递单号:"+selectExpressLliset[i][2]);
                    System.out.print("||");
                    System.out.println("快递公司:"+selectExpressLliset[i][3]);
                }
            }
            return 1;
        }
        return 0;
    }
}
